package com.scf.fruit.shiro.impl;

import com.scf.fruit.enums.StatusEnum;
import com.scf.fruit.shiro.RoleDto;
import com.scf.fruit.shiro.RoleService;
import com.scf.fruit.shiro.dao.RoleMapper;
import com.scf.fruit.util.IDUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * @author : 孙超飞
 * @title :
 * @description :
 * @date : 2018-04-23 10:47
 */
@Service
public class RoleServiceImpl implements RoleService {
    @Resource
    private RoleMapper roleMapper;
    @Override
    public List<RoleDto> queryRoleByList(Collection<Long> collection) {
        if(CollectionUtils.isEmpty(collection)){
            return null;
        }else
        {
            Example example=new Example(RoleDto.class);
            Example.Criteria criteria=example.createCriteria();
            criteria.andIn("id",collection);
            return roleMapper.selectByExample(example);
        }

    }

    @Override
    public boolean insert(RoleDto dto) {
        dto.setId(IDUtil.getId());
        dto.setCreateTime(new Date());
        dto.setDeleteFlag(StatusEnum.YES.getValue());
        return roleMapper.insert(dto)>0;
    }
}
